<?php
namespace app\index\controller;
use think\Controller;
use acextend\send;
use Lcobucci\JWT;
use think\Db;
class Extra extends Base
{
    public function index()
    {
    }

    /***
     *   外送单位检索
     */
    public function Outgoing()
    {
        $data = Db::query("SELECT * FROM S_SampleDetail  A INNER JOIN S_SampleItem B ON A.ID = B.S_SampleId 
        WHERE  S_SampleTime BETWEEN  '2021-03-04'    AND '2021-03-10' AND A.yqdh = '外包标本'  and  S_shosiptal = '杭州千麦' and outhosiptal !='杭州千麦'
        ");
        if($data){
            $this->assign('data',$data);
            return $this->fetch('extra/outgoing');
        }
    }

    /***
     *   外送单位检索  --by time
     */
    public function OutgoingBytime($S_SampleTime)
    {
        $S_SampleTime = $_GET['S_SampleTime'];
        $S_SampleTimeafter = date("Y-m-d",strtotime("+1 day",strtotime($S_SampleTime)));
        $data = Db::query("SELECT * FROM S_SampleDetail  A INNER JOIN S_SampleItem B ON A.ID = B.S_SampleId 
        WHERE  S_SampleTime BETWEEN  :S_SampleTime    AND  :S_SampleTimeafter AND A.yqdh = '外包标本'   and  S_shosiptal !=  outhosiptal
        ",['S_SampleTime'=>$S_SampleTime,'S_SampleTimeafter'=>$S_SampleTimeafter]);

        if($data){
            return layshow('0','success',20, $data);
        }
        return layshow('0','error',20, $data);
    }

    /***
     *   项目对照修改
     */
    public function JymdDy()
    {
        //send::push();
        return $this->fetch('extra/JymdDy');
    }
    /***
     *   项目对照修改
     */
    public function JymdDyAlter(){
        $oldjymddm_zx = $_POST['oldjymddm_zx'];
        $newjymddm_zx = $_POST['newjymddm_zx'];
        $newjymdmc_zx = $_POST['newjymdmc_zx'];
        if (empty($oldjymddm_zx) || empty($newjymddm_zx) || empty($newjymdmc_zx)){
            $this->success('修改失败 不能为空','extra/JymdDy');
        }
        //先找到旧的检验目的代号
        $res = Model('extra')->MJymdDyAlter($oldjymddm_zx,$newjymddm_zx,$newjymdmc_zx);
        if($res){
            //开始记录日志
            Model('Log')->addLog("修改了一批项目对照.$oldjymddm_zx.改为了.{$newjymddm_zx}.**", 1, $newjymddm_zx);
            $this->error('修改成功','extra/JymdDy');
        }
            $this->success('修改失败','extra/JymdDy');
    }

    /***
     *   废板处理操作
     */
    public function abandon(){
        return $this->fetch('extra/abandon');
    }
    /***
     *   废板处理操作--根据号码
     */
    public function abandonBySracknumber(){
            $sracknumber = $_POST['sracknumber'];
            $res = Model('extra')->MgetabandonBySracknumber($sracknumber);

            if(!$res){
                $this->error('删除失败  没有该孔位的数据','extra/abandon');
            }
            //开始删除
            $res = Model('extra')->MabandonBySracknumber($sracknumber);
            if(!$res){
                $this->error('删除失败  请检查','extra/abandon');
            }
            //开始记录
            Model('Log')->addLog("删除了一个孔位.$sracknumber.**", 1, $sracknumber);
            $this->success('删除成功','extra/abandon');
    }
    /***
     *   废板处理操作--批量
     */
    public function abandonByUsednum(){
         $usednum = $_POST['usednum'];
         $res = Model('extra')->MabandonByUsednum($usednum);
        //开始记录
        Model('Log')->addLog("删除了一批孔位 小于.$usednum.**", 1, $usednum);
        $this->success('删除成功','extra/abandon');
    }
    /***
     *    检验目的 对照 修改
     */
    /***
     * 微生物修改 结算 sfzt
     */
    public function Delewswsf(){
        return $this->fetch('extra/delewswsf');
    }

    public function DelewswsfData(){
        $byh = $_POST['byh'];
        if(empty($byh)){
            $this->success('删除失败 不能为空','extra/Delewswsf');
        }
        $da= Db::execute("UPDATE xj_ybxx SET sfzt = null WHERE byh = :byh ",['byh'=>$byh]);
        if($da){
            //开始记录
            Model('Log')->addLog("修改了一个微生物sf状态.$byh.**", 1, $byh);
            $this->success('删除成功','extra/Delewswsf');
        }
        $this->success('删除失败','extra/Delewswsf');
    }

}